package com.atguigu.srb.core.service.impl;

import com.atguigu.srb.core.mapper.*;
import com.atguigu.srb.core.pojo.dto.PutChallengeTable;
import com.atguigu.srb.core.pojo.dto.PutCooperationTable;
import com.atguigu.srb.core.pojo.entity.*;
import com.atguigu.srb.core.service.ApplyActService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ApplyActImpl extends ServiceImpl<CommunityActivitiesMapper,CommunityActivities> implements ApplyActService {

    @Resource
    private CommunityMemberInformationMapper communityMemberInformationMapper;
    @Resource
    private ChallengeTableMapper challengeTableMapper;
    @Resource
    private CommunityInformationMapper communityInformationMapper;
    @Resource
    private CooperationTableMapper cooperationTableMapper;

    @Override
    public boolean increasemember(ClubRegistration clubRegistration) {
        try {
            CommunityMemberInformation communityMemberInformation = new CommunityMemberInformation();
            BeanUtils.copyProperties(clubRegistration,communityMemberInformation);
            communityMemberInformationMapper.insert(communityMemberInformation);
            return true;
        }catch (Exception e)
        {
            return false;
        }

    }

    @Override
   public List<CommunityMemberInformation> getByNumber(String communitynumber){


      List<CommunityMemberInformation> communityMemberInformations = communityMemberInformationMapper.selectByCommunityNumber(communitynumber);

      return communityMemberInformations;
    }

    @Override
    public Boolean putchallenge(PutChallengeTable putChallengeTable) {
        ChallengeTable challengeTable = new ChallengeTable();
        BeanUtils.copyProperties(putChallengeTable,challengeTable);
        challengeTable.setStatus("待确认");
        LocalDateTime localDateTime = LocalDateTime.now();
        challengeTable.setCreatedTime(localDateTime);
        challengeTable.setWinningClubNumber("无");
        System.out.println("执行插入");
        challengeTableMapper.insert(challengeTable);
        System.out.println("执行插入完成");
        return true;
    }

    @Override
    public List<ChallengeTable> getchallengtable(String communitynumber) {

       List<ChallengeTable> challengeTables =challengeTableMapper.selectByRespondingClubNumber(communitynumber);


        return challengeTables;
    }

    @Override
    public Boolean confirmchallenge(int id, String data) {
        ChallengeTable challengeTable = challengeTableMapper.selectById(id);
        challengeTable.setStatus(data);

       challengeTableMapper.updateById(challengeTable);
       return true;

    }

    @Override
    public String challengeresutl(int id, String data) {
        ChallengeTable challengeTable = challengeTableMapper.selectById(id);
        challengeTable.setWinningClubNumber(data);
        challengeTableMapper.updateById(challengeTable);

        CommunityInformation communityInformation =  communityInformationMapper.selectByNumber(data);
        return communityInformation.getCommunityName();
    }

    @Override
    public Boolean putcooperation(PutCooperationTable putCooperationTable) {
        CooperationTable cooperationTable = new CooperationTable();
        BeanUtils.copyProperties(putCooperationTable,cooperationTable);
        cooperationTable.setStatus("待确认");
        LocalDateTime localDateTime=LocalDateTime.now();
        cooperationTable.setCreatedTime(localDateTime);
        cooperationTableMapper.insert(cooperationTable);
        return true;

    }

    @Override
    public List<CooperationTable> getcooperation(String communitynumber) {
        List<CooperationTable> cooperationTables = cooperationTableMapper.selectByRespondingClubNumber(communitynumber);


        return cooperationTables;
    }

    @Override
    public Boolean confirmcooperation(int id, String data) {
        CooperationTable cooperationTable = cooperationTableMapper.selectById(id);
        cooperationTable.setStatus(data);
        cooperationTableMapper.updateById(cooperationTable);
        return  true;
    }

    @Override
    public List<ChallengeTable> getchall(String communitynumber) {
        List<ChallengeTable> challengeTables =challengeTableMapper.selectByRespondingClubNumber03(communitynumber);


        return challengeTables;
    }

    @Override
    public List<CooperationTable> getcooper(String communitynumber) {
        List<CooperationTable> cooperationTables = cooperationTableMapper.selectByRespondingClubNumber03(communitynumber);


        return cooperationTables;
    }
}

